package com.ruoyi.employment.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.employment.domain.TAssist;
import com.ruoyi.employment.dto.AssistDto;
import com.ruoyi.employment.service.ITAssistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 就业帮扶Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/assist")
public class TAssistController extends BaseController
{
    @Autowired
    private ITAssistService tAssistService;

    /**
     * 查询就业帮扶列表
     */
    @RequiresPermissions("employment:assist:list")
    @GetMapping("/list")
    public TableDataInfo list(TAssist tAssist)
    {
        startPage();
        List<TAssist> list = tAssistService.selectTAssistList(tAssist);
        return getDataTable(list);
    }

    /**
     * 导出就业帮扶列表
     */
    @RequiresPermissions("employment:assist:export")
    @Log(title = "就业帮扶", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAssist tAssist)
    {
        List<TAssist> list = tAssistService.selectTAssistList(tAssist);
        ExcelUtil<TAssist> util = new ExcelUtil<TAssist>(TAssist.class);
        util.exportExcel(response, list, "就业帮扶数据");
    }

    /**
     * 获取就业帮扶详细信息
     */
    @RequiresPermissions("employment:assist:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAssistService.selectTAssistById(id));
    }

    /**
     * 新增就业帮扶
     */
//    @RequiresPermissions("employment:assist:add")
    @Log(title = "就业帮扶", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAssist tAssist)
    {
        return toAjax(tAssistService.insertTAssist(tAssist));
    }

    /**
     * 修改就业帮扶
     */
    @RequiresPermissions("employment:assist:edit")
    @Log(title = "就业帮扶", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAssist tAssist)
    {
        return toAjax(tAssistService.updateTAssist(tAssist));
    }

    /**
     * 删除就业帮扶
     */
    @RequiresPermissions("employment:assist:remove")
    @Log(title = "就业帮扶", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAssistService.deleteTAssistByIds(ids));
    }

    /**
     * 移交就业帮扶
     */
    @RequiresPermissions("employment:assist:query")
    @PostMapping(value = "/transfer")
    public AjaxResult handOver(@RequestBody AssistDto assistDto)
    {
        return success(tAssistService.handOver(assistDto));
    }

    /**
     * 完成就业帮扶
     * @param id
     * @return
     */
    @GetMapping(value = "/finish/{id}")
    public AjaxResult finish(@PathVariable("id") Long id)
    {
        return success(tAssistService.assistFinish(id));
    }

    /**
     * 获取就业帮扶详细信息
     */
    @PostMapping(value = "/getAssist")
    public AjaxResult getAssist(@RequestBody AssistDto assistDto)
    {
        return success(tAssistService.getAssist(assistDto.getCode()));
    }

}
